//
//  ViewController.m
//  5.4treeNavigation
//
//  Created by h92 on 14/12/23.
//  Copyright (c) 2014年 李腾飞. All rights reserved.
//

#import "ViewController.h"
#import "CityViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation ViewController

@synthesize tableView;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 两个或自己都干了
//    self.tableView.delegate = self;
//    self.tableView.dataSource = self;
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    
    
    // 读取文件信
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *path = [bundle pathForResource:@"provinces_cities" ofType:@"plist"];
    
    
    // 保存文件信息
    self.dictData = [[NSDictionary  alloc] initWithContentsOfFile:path];
    
    self.listData = [self.dictData allKeys];
    
    self.title = @"城市信息";

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 实现表视图数据源方法 

// 干活 返回行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.listData count];
}

// 输入省内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
//    if(cell==nil)
//    {
//        cell=[[UITableView alloc] initWithS]
//    }
//    
    NSInteger row = [indexPath row];
    cell.textLabel.text = [self.listData objectAtIndex:row];
    return cell;
}


#pragma 实现table协议的职责
//选择表视图行时候触发

// 从cell上穿越
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"cell被点击");
    // 实现跳转
    if([segue.identifier isEqualToString:@"ShowSelectedProvince"])
    {
        //穿越目标
        CityViewController *citiesViewController = segue.destinationViewController;
        
        NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
        NSString *selectName = [self.listData objectAtIndex:selectedIndex];
        NSLog(@"error 1");
        citiesViewController.listData = [self.dictData objectForKey:selectName];
        NSLog(@"error 2");
        citiesViewController.title = selectName;
        NSLog(@"error 3");
    }
}





















@end
